package com.zenithsun.news.newsinfo.model;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrQuery.ORDER;

import com.zenithsun.common.bean.SolrSearch;

/**
 * solr查询条件
 * @author wanglei@enersun.com.cn
 * @createTime 2016-7-20 11:35:10
 */
public class NewsSolrSearch extends SolrSearch<Newsinfo> {
	
	public NewsSolrSearch(Newsinfo newsinfo,int start,int limit,boolean hightlight){
		super(newsinfo,start,limit,hightlight);
	}
	
	@Override
	public void createSearchCondition() {
		if(this.getSearch()!=null){
			StringBuffer sb=new StringBuffer();
			if(StringUtils.isNotBlank(this.getSearch().getTitle())){
				sb.append("(title_mmseg4j:").append(this.getSearch().getTitle())
				.append(" OR ")
				.append("subTitle_mmseg4j:").append(this.getSearch().getTitle())
				.append(" OR ")
				.append("nabstract_mmseg4j:").append(this.getSearch().getTitle())
				.append(" OR ")
				.append("content_mmseg4j:").append(this.getSearch().getTitle())
				.append(" OR ")
				.append("keyword_mmseg4j:").append(this.getSearch().getTitle())
				/*
				if(RegExUtil.isDate(this.getSearch().getTitle())){
					sb.append(" OR ")
					.append("publishTime_mmseg4j:").append(this.getSearch().getTitle());
				}
				*/
				.append(" OR ")
//				.append("(coverPath_mmseg4j:").append(this.getSearch().getTitle())
//				.append(" OR ")
				.append("publishGroup_mmseg4j:").append(this.getSearch().getTitle())
				.append(")");
			}
			if(StringUtils.isNotBlank(this.getSearch().getType())){
				if(sb.length()>0){
					sb.append(" AND ");
				}
				sb.append(" type_mmseg4j:").append(this.getSearch().getType());
			}
			if(this.getSearch().getNewsColumns()!=null&&StringUtils.isNotBlank(this.getSearch().getNewsColumns().getId())){
				if(sb.length()>0){
					sb.append(" AND ");
				}
				sb.append(" column_mmseg4j:").append(this.getSearch().getNewsColumns().getId());
			}
			if(this.getSearch().getState()>-1){
				if(sb.length()>0){
					sb.append(" AND ");
				}
				sb.append(" state_mmseg4j:").append(this.getSearch().getState());
			}
			if(sb.length()==0){
				sb.append("*");
			}
			//sb.append(" ORDER BY coverPath_mmseg4j DESC ");
			
			this.setSearchCondition(sb.toString());
		}
		
	}

//	@Override
//	public void createOrder() {
//		Map<String, ORDER> map=new HashMap<String, ORDER>();
//		map.put("isTop_mmseg4j", SolrQuery.ORDER.desc);
//		map.put("publishTime_mmseg4j", SolrQuery.ORDER.desc);
//		this.setOrderMap(map);
//	}
}